<template>
  <forms ref="forms" :config="config" @submit:forms="onsubmit" :btns="btns">
    <template #dividend_money_value="{row}">
      <p>{{ dividend_money_value }}</p>
    </template>
  </forms>
</template>

<script>
import {iframe} from "@/js/tool.js";
import {ajax} from "@/js/api_tool.js";

export default {
  props: ['__iframe'],
  data(){
    let id = this.$get('id'), btns = undefined;

    let forms_config = {
      pay_money:{name:'pay_money', label:'支付金额', type:'text_one', config:'number', value:0, tips:'给当前分红池添加虚拟业绩'},
      dividend_ratio:{name:'dividend_ratio', label:'分红比例', type:'text_one', config:'number', value:0, tips:'虚拟业绩的分红比例，如果只增加业绩，不增加分红，设置为0'},
      dividend_money: {name:'dividend_money', label:'分红金额', type:'dividend_money_value', value:0, tips:'预计会增加的分红金额'},
    }
    if (id){
      forms_config.create_time = {label:'创建时间',name:'create_time',tips:''};
    }
    if (this.$get('is_info')){
      s94Mjs.each(forms_config, function (row){ row.is_info = true; });
      btns = [];
    }
    return {
      id: id,
      btns: btns,
      config: forms_config,
    }
  },
  methods: {
    onsubmit(formData){
      ajax({url:'/admin/log_dividend/add_money', method:'POST', data:formData}, (res)=>{
        if (this.__iframe){
          iframe.exe('log_dividend/index_money', '$refs.list_url.list');
          iframe.exe('log_dividend/index', '$refs.list_url.list');
          iframe.hide('log_dividend/edit_money');
          if (!this.id) this.$refs['forms'].init();
        }else {
          this.$router.push('index');
        }
      }, (res)=>{
        if (res.errors) this.$refs['forms'].errors = res.errors;
      })
    }
  },
  computed:{
    dividend_money_value(){
      return Math.floor(this.config.pay_money.value * this.config.dividend_ratio.value) / 100;
    }
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;


    //其他初始化操作

  }
}
</script>
